// pages/login/index.js
import config from '../../config/index.js'
import wxRequest from '../../utils/wxRequest.js'
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '', //账号
    password: '', //密码
    show: true, //显示密码
    test_name: '',
    test_pwd: '',
    status: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.request({
      url: config.domain + '/toolkit/index/status',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        if (res.data.data.type == 1) {
          that.setData({
            test_name: res.data.data.username,
            test_pwd: res.data.data.password,
            status: true
          });
        }
      }
    })
  },
  getName(e) { //获取账号
    this.setData({
      name: e.detail.value.trim()
    });
  },
  getPwd(e) { //获取密码
    this.setData({
      password: e.detail.value.trim()
    });
  },
  loginFn(e) { //登录事件
    var that = this;
    wxRequest.login({
      username: that.data.name,
      password: that.data.password
    }, app);

  },
  showPwd() {
    this.setData({
      show: !this.data.show,
      password: this.data.password
    });
  }

})